<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="stylesheet" href="../../css/allBase.css">
		<link rel="stylesheet" href="../../css/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" href="../../css/tables.css">
		<link rel="stylesheet" href="../../css/dialog.css" />
		<link href="../../js/riqi/bootstrap.min.css" rel="stylesheet">
		<link href="../../js/riqi/font-awesome.min.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" media="all" href="../../js/riqi/daterangepicker-bs3.css" />
		<style>
			#main1 {
				width: 98%!important;
				height: 100%!important;
			}
			
			.panel-body {
				margin: 2% auto;
				width: 100%;
				padding-bottom: 0 auto;
				height: 100%;
				margin-top: 0;
			}
			
			#btncx {
				top: 0;
			}
			
			.title1 {
				width: 100%;
				height: 470px;
				position: relative;
			}
			
			.title1 .tishi {
				position: absolute;
				top: 20px;
				left: 170px;
				color: red;
			}
			
			#main1 {
				width: 100%;
				height: 470px;
				margin-top: 0;
			}
			
			.classified-search {
				margin-bottom: 0;
			}
			
			#main1 p {
				font-size: 22px;
				margin: 0;
				margin-bottom: 2px;
			}
			
			#main1 {
				/*		position: relative;
    		top: 0px;
    		color: red;*/
			}
			
			#nrdvMsgBox {
				z-index: 99999;
			}
			
			#nrShowBolightBox {
				z-index: 9999;
			}
			.timerow td{
				text-align: center!important;
			}
			td:last-child{
				/*border-right:1px solid #ddd!important;*/
			}
			.mt-20{
				padding:10px 50px;
			}
           .tableBox{
        	    padding-top: 10px;
			    padding-bottom: 10px;
			    margin-left: 1%;
			    margin: 2% auto;
			    width: 98%;
			    /*min-height: 550px;*/
			    background-color: #fff;
			    box-shadow: 3px 3px 20px 3px #ddd;
			}
			.text-c{
				background: #55bde4;
			}
			.timerow td {
			    background: #fdfdfd!important;
			    color: #313B4B!important;
			    font-weight: 400!important;
			}
			.text-c td{
				color:#fff;
			}
			.paixu img,.paixu2 img,.paixu3 img{
			     transform:rotate(180deg);
			     cursor: pointer;
			}
		</style>
		<![endif]-->
    <title>结果</title>

</head>
<body>
	<div class="classifiedBox">
	     <div class="classified-search">
             <form class="form-horizontal" style="margin-bottom: 5px;">
                 <fieldset>
                  <div class="control-group">
                    <div class="controls">
                    <p style="float: left;line-height: 34px;">日期范围：</p>
                     <div class="input-prepend input-group" style="float: left;width:150px;">
                     	<!--<div id="reservation" class="pull-left dateRange" style="width: 210px;background-color: #eee;border: 1px solid #ccc;border-radius: 4px;padding: 2px 7px;margin-top: 4px;">  
	                        <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>  
	                        <span id="searchDateRange"></span>  
	                        <b class="caret"></b>  -->
	                    <span class="add-on input-group-addon">
                     		<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
                     	</span>
                     	<input type="text" readonly style="width: 200px" name="reservation" id="reservation" class="form-control" value="2017-7-21 - 2017-7-21" />
                   </div>
                     <p class="meici" style="float:left;color:red;line-height: 34px;">（每次最多选取60天）</p>
                    </div>
                  </div>
                 </fieldset>
              </form>
	        <div class="product-classification">
	            <div class="productR">
	                科目分类：
	            </div>
	            <div class="productL">
	                <span id="hszynew"  class="selected">护士执业</span>
	                <i>（*单选）</i>
	            </div>
	            <!--<div class="singleApp">
	            	
	            </div>-->
	        </div>
	         <div class="purchase-situation">
	                  人群分类：
            <span class="selected" id="2">合计</span><span id="1">购买用户</span><span id="0">未购买的注册用户</span>（*单选）
	        </div>
	        <div class="selection-classification">
	        页面分类：
	        <span class="selected">首页</span><span>课程</span><span>练习</span><span>评测</span><span>我的</span><span>更多</span>
	        </div>
	        <button id="btncx" onclick="" class="btn btn-success" type="submit">开始查询</button>
	        <!--<div class="refresh">
	            <img src="../../img/refresh.png" alt="">
	            <a class="tabReload" href="#">刷新当前</a>
	        </div>-->
	    </div>
	</div>
    <!--数据展示结果-->
    <img class="loadingimg" src="../../img/loading.gif" style="position: absolute; top: 0%; left: 0; right: 0; bottom: 0; margin: auto;display: none;" />
    <div class="panel-body" style="display: none;">
    	<div class="titleNum"></div>
    	<div class="title" style="width:100%">
    		<ul class="title1" >
    			<p class="tishi">*点击量越大，展示模块越大(如展示为空，说明此功能数据为0)</p>
    			<li id="main1" class="main">
    				
    			</li>
    		</ul>
    	</div>
        
    </div>
    <!--数据展示结果-->
    <div class="tableBox" style="display: none;">
    	<div class="mt-20">
			<table id="reptable1" class="table table-border table-bordered table-bg table-hover table-sort" cellspacing="0" cellpadding="0">
				<thead class="thead1" >
					
				</thead>
				
			</table>
	    </div>
    </div>
    <script src="../../js/jquery/jQuery-2.2.0.min.js"></script>
    <!--<script src="../js/charts/Chart.js"></script>-->
    <script type="text/javascript" src="../../js/base/echarts.common.min.js"></script>
      <script type="text/javascript" src="../../js/base/echarts.js"></script>
    <script type="text/javascript" src="../../js/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="../../js/base/ajax.js"></script>
    <script type="text/javascript" src="../../js/base/yingSoftPrg.js"></script>
	<script type="text/javascript" src="../../js/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="../../js/base/dialog.js"></script>
    <script type="text/javascript" src="../../js/riqi/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../js/riqi/moment.js"></script>
    <script type="text/javascript" src="../../js/riqi/daterangepicker.js"></script>
    <script type="text/javascript">
            var myDate = new Date();//添加日期
               	y=myDate.getFullYear(); 
               	m=myDate.getMonth()+1;
               	d=myDate.getDate()-1;
               	if(myDate.getDate()==1){
               		 d=myDate.getDate();
               	}
               	dqy=y+"-"+m+"-"+d;
               	$('#reservation').val(dqy+" - "+dqy)
//             	  $('#reservation span').html(dqy + ' - ' +dqy);
               $(document).ready(function() {
                  $('#reservation').daterangepicker({
                        // startDate: moment().startOf('day'),  
                        //endDate: moment(),  
                        //minDate: '01/01/2012',    //最小时间  
                        maxDate : moment(), //最大时间   
                        dateLimit : {  
                            days : 60  
                        }, //起止时间的最大间隔  
                        showDropdowns : true,  
                        showWeekNumbers : false, //是否显示第几周  
                        timePicker : false, //是否显示小时和分钟  
                        timePickerIncrement : 60, //时间的增量，单位为分钟  
                        timePicker12Hour : false, //是否使用12小时制来显示时间  
                        ranges : {  
                            //'最近1小时': [moment().subtract('hours',1), moment()],  
                            '昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
                            '最近7日': [moment().subtract('days', 6), moment()],  
                            '最近30日': [moment().subtract('days', 29), moment()],  
                            '最近60日': [moment().subtract('days', 59), moment()]  
                        },  
                        opens : 'right', //日期选择框的弹出位置  
                        buttonClasses : [ 'btn btn-default' ],  
                        applyClass : 'btn-small btn-primary blue',  
                        cancelClass : 'btn-small',  
                        format : 'YYYY-MM-DD', //控件中from和to 显示的日期格式  
                        separator : ' - ',  
                        locale : {  
                            applyLabel : '确定',  
                            cancelLabel : '取消',  
                            fromLabel : '从',  
                            toLabel : '到',  
                            weekLabel: 'W',
                            customRangeLabel : '选择时间',  
                            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],  
                            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',  
                                    '七月', '八月', '九月', '十月', '十一月', '十二月' ]
//                          firstDay : 1  
                        }  
                    }, function(start, end, label) {//格式化日期显示框  
                        $('#reservation span').html(start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));  
                    }); 
					
               });
               $(document).on('click','.applyBtn',function(){//判断日期是否是在60天之内
               		var val=$('#reservation').val().split(' - ');
		          	var endTime=new Date(val[1]);
		          	var startTime=new Date(val[0]);
		          	if(endTime - startTime>5270400000){
		          		$('.daterangepicker').css('display','block')
		          		G_Prg.alert('每次最多选取60天');
		          	}
               })
               var clients = [];
        	   var clientsName = [];
               var hTimes = ["0点","1点","2点","3点","4点","5点","6点","7点","8点","9点",
    				"10点","11点","12点","13点","14点","15点","16点","17点","18点","19点",
    				"20点","21点","22点","23点"
    				];
            this.init = function(){
                var option = {};
                var dd=new Date();
                var m=dd.getMonth()+1;
                var d1=dd.getDate();
                //var d2=dd.getDate();
                var days1=G_Prg.GetDay(dd.getFullYear(),m,d1);
                var days2=  dd.getFullYear()+'-'+m+'-'+d1;
                $('#logmin').val(days1);
                $('#logmax').val(days1);
                allclick();//点击事件

            }

            /**************************************************
             * 功能：点击事件
             * 函数名：allclick（）
             * 传入参数：无
             * 创建人：刘淳昊 2017-03-13
             *************************************************/
            function allclick() {
                //刷新页面
                $('.refresh').on('click',function(){
                    window.location.reload();
                })
                //切换情况选项
                $('.purchase-situation span').on('click',function(){
                    if($(this).hasClass('selected')){
                        $(this).removeClass('selected');
                    }else{
                        $(this).addClass('selected').siblings().removeClass('selected');
                    }
                })
                //页面切换选项
                $('.selection-classification span').on('click',function(){
                	if($(this).hasClass('selected')){
                        $(this).removeClass('selected');
                    }else{
                        $(this).addClass('selected').siblings().removeClass('selected');
                    }
                })
                //查询结果
                $('#btncx').on('click',function(){
	                var val=$('#reservation').val().split(' - ');
	                var startTime=new Date(val[0]);
	                var endTime=new Date(val[1]);
	                if(endTime-startTime<5270400000){
	                	$('.setpNum li').html('0');
	                    $('.loadingimg').show();
	                	$('.panel-body').hide();
	                	setTimeout(function(){
	                		$('.panel-body').show();
		                    getdata();//获取数据
		                    window.onresize = function () {
						        swChart.resize();
						    }
	                	},500)
	                }else{
	               		G_Prg.alert('每次最多选取60天',function(){
			
		                });
	                }
                })

            }
            /**************************************************
             * 功能：新版护士职业功能点击人数 /api/new/userclicknewcount
             * 接口：https://tongji.ksbao.com:8003
             * 函数名：getdata（）
             * 传入参数：startDay: 开始时间
		                endDay: 结束时间
		                userType: 用户类型
		                clients: 产品分类 json 单选
             * 创建人：赵梦琦 2017-10-24
             *************************************************/
            function getdata(locationPage){
                var val=$('#reservation').val().split(' - ');
                var startTime = val[0];
                var endTime = val[1];
                clients=['hszynew'];
                clientsName=['护士执业'];
                var userType = $('.purchase-situation .selected').attr('id');
                var clientsData = JSON.stringify(clients);
                var locationPage = $('.selection-classification .selected').text();
                var times=[];
                getAll(startTime,endTime);
                function getAll(begin,end){
				    var ab = begin.split("-");
				    var ae = end.split("-");
				    var db = new Date();
				    db.setUTCFullYear(ab[0], ab[1]-1, ab[2]);
				    var de = new Date();
				    de.setUTCFullYear(ae[0], ae[1]-1, ae[2]);
				    var unixDb=db.getTime();
				    var unixDe=de.getTime();
				    for(var k=unixDb;k<=unixDe;){
					    times.push((new Date(parseInt(k))).format());
					    k=k+24*60*60*1000;
				    }
				}
                var _url='/api/new/userclickNewDistribution?startDay='+startTime+'&endDay='+endTime+'&userType='+userType+'&location='+locationPage;
                G_AjaxApi.get(_url,false,function(json){
//              G_AjaxApi.get(_url,false,function(json){
                    var jsonData = JSON.parse(json);
					
                    if(jsonData.status ==200){
                        if(jsonData.data ==[ ]){
                            alert('数据为空');
                        }else{
                            var _data = jsonData.data;
//                          var _total = jsonData.total;
                            var total = 0;
                            for(var i=0;i<_data.length;i++){
                            	total += _data[i].count;
                            }
                            Canvas1(_data,total);
                            $('.loadingimg').hide();
                             //表格图 
                        $('.loadingimg').hide();
                    	$('.tableBox').css('display','block');
                    	$('.thead1 tr').remove();
						var nowstr = '<tr class="text-c" style="padding:15px;"><td valign="middle" width="25%" style="padding:15px;">功能</td><td style="padding:15px;" valign="middle" width="25%">功能点击量占比<span class="paixu" style="margin-left:25px;"><img src="../../img/paixu.png"></td>'+
						'<td valign="middle" width="25%" style="padding:15px;">功能点击量<span class="paixu2" style="margin-left:25px;"><img src="../../img/paixu.png"></span></td><td valign="middle" width="25%" style="padding:15px;" >功能点击人数<span class="paixu3" style="margin-left:25px;"><img src="../../img/paixu.png"></span></td></tr>';
						$('.thead1').append(nowstr);

						for(var i =_data.length-1;i>=0;i--){
							var strTr= '<tr class="timerow">'+
										'<td valign="middle" style="padding:15px;">'+ _data[i].btnName +'</td>'+
										'<td valign="middle" style="padding:15px;">'+ (_data[i].count/total*100).toFixed(2)+'%' +'</td>'+
										'<td valign="middle" style="padding:15px;">'+ _data[i].count+'</td>'+
										'</tr>';
							$('.text-c').after(strTr);
						}
						$(".timerow").each(function(i){
						    for(var j= 1;j<2;j++){
								var strTd ='<td valign="middle" style="padding:15px;">'+_data[i].num+'</td>';
								$(this).append(strTd);
							}
						});
                        }
                    }else{
                        console.log(jsonData.status)
                    }
                })
                 $(document).on('click','.paixu',function(){
	        dataSort(1,this)
        })
        $(document).on('click','.paixu2',function(){
	        dataSort(2,this)
        })
        $(document).on('click','.paixu3',function(){
	        dataSort(3,this)
        })
        function dataSort(num,data){
        	var oTab=document.querySelector('.thead1');
	        var arr=[];
	        for(i=0;i<oTab.rows.length-1;i++){
	           arr[i]=oTab.rows[i+1]
	        }
			if($(data).attr("px") == 1){
				$(data).find('img').css({'transform':'rotate(180deg)'})
				 arr.sort(function(tr1,tr2){
					  var sub1=tr1.cells[num].innerHTML;
					  var sub2=tr2.cells[num].innerHTML;
					  if(num == 1){
					  	  var sub1=sub1.replace(/%/, "");
					      var sub2=sub2.replace(/%/, "");
					  }
				      var n1=parseFloat(sub1);  
				      var n2=parseFloat(sub2);
				      return n1-n2;
			     })
				$(data).attr("px",0);
			}else{
				$(data).find('img').css({'transform':'rotate(0deg)'})
				 arr.sort(function(tr1,tr2){
					  var sub1=tr1.cells[num].innerHTML;
					  var sub2=tr2.cells[num].innerHTML;
					  if(num == 1){
					  	  var sub1=sub1.replace(/%/, "");
					      var sub2=sub2.replace(/%/, "");
					  }
				      var n1=parseFloat(sub1);  
				      var n2=parseFloat(sub2);
				      return n2-n1;
			     })
				$(data).attr("px",1);
			}
		
	        for(i=0;i<arr.length;i++){
	          oTab.append(arr[i])
	        }
        }
            }
            /**********************************************************
            * 功能：获取日期区间
            * ********************************************************/
            function getDate(datestr){
                var temp = datestr.split("-");
                var date = new Date(temp[0],temp[1],temp[2]);
                return date;
            }
            Date.prototype.format=function (){
			    var s='';
			    s+=this.getFullYear()+'-';          // 获取年份。
			    s+=(this.getMonth()+1)+"-";         // 获取月份。
			    s+= this.getDate();                 // 获取日。
			    return(s);                          // 返回日期。
			};
			function getAll(begin,end){
				times=[];
			    var ab = begin.split("-");
			    var ae = end.split("-");
			    var db = new Date();
			    db.setUTCFullYear(ab[0], ab[1]-1, ab[2]);
			    var de = new Date();
			    de.setUTCFullYear(ae[0], ae[1]-1, ae[2]);
			    var unixDb=db.getTime();
			    var unixDe=de.getTime();
			    for(var k=unixDb;k<=unixDe;){
				    times.push((new Date(parseInt(k))).format());
				    k=k+24*60*60*1000;
			    }
			}
			 /**************************************************
         * 功能：功能排布
         * 函数名：Canvas1（）
         * 传入参数：无
         * 创建人：赵梦琦 2017-10-27
         *************************************************/
		function Canvas1(dataName,total){
		  	swChart = echarts.init(document.getElementById('main1'));
		  	var series=[];
		  	var trueRate = 0.00;
		  	var Item = function(){
                return {
                    name:'',
                    value:'',
                    value2:'',
                    rate:'',
                }
            };
		  	for(var i=0;i<dataName.length;i++){
		  	 	if(dataName.length > 1){
		            var it = new Item();
		            it.name = dataName[i].btnName;
		            it.value = dataName[i].count;
		            it.value2 = dataName[i].num;
		            it.rate = dataName[i].count/total;
		            series.push(it);// 将Itemsin放在series中
		        }
		  	}
			var option = {
	            tooltip : {
                   show: true,
                   trigger: 'item',
                   //show: true,   //default true
                   showDelay: 0,//显示延时，添加显示延时可以避免频繁切换
                   hideDelay: 20,//隐藏延时
                   transitionDuration: 0.2,//动画变换时长
                   backgroundColor: 'rgba(0,0,0,0.7)',//背景颜色（此时为默认色）
                   borderRadius: 8,//边框圆角
                   padding: 20,    // [5, 10, 15, 20] 内边距
                   position: function (p) {
                       return [p[0] + 10, p[1] - 10];
                   },
                   formatter: function (params,ticket,callback) {
                      var res = '';  
		              var myseries = option.series;  
		              for (var i = 0; i < myseries.length; i++) {  
		                   for(var j=0;j<myseries[i].data.length;j++){  
		                        if(myseries[i].data[j].name==params.name){
		                        	   res+= "<p>"+parseInt(myseries[i].data[j].rate*100)+'%</p>'; 
		                        	   res+= myseries[i].data[j].name+'<br/>';  
		                               res+=' 点击量: '+myseries[i].data[j].value+'</br>';  
		                               res+=' 点击人数: '+myseries[i].data[j].value2+'</br>';
		                         }  
		                   }         
		              }  
		              return res;  
                   }
	        	},
	            grid: {
                    left: '0%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true,
                    x:130
                },
	        	calculable : true,
		        series : [
		            {
		                name:"数据",
		                type:'treemap',
		                roam:false,
		                nodeClick:false,
		                drillDownIcon:false,
		                breadcrumb:false,//去下面提示
		                itemStyle: {
		                    normal: {
		                        label: {
		                            show: true,
		                            formatter: "{b}",
		                            textStyle:{
				                         // 用 itemStyle.normal.label.textStyle.fontSize 來更改餅圖上項目字體大小
				                         fontSize: 18
		                            }
		                        },
				                grid: {
	                                left: '50%',
	                                right: '4%',
	                                bottom: '3%',
	                                containLabel: true,
	                                x:130
	                            },
		                        borderWidth: 1
		                    },
		                    emphasis: {
		                        label: {
		                            show: true
		                        }
		                    }
		                },
		                data:series
		            }
		        ]
	  		};
			// 使用刚指定的配置项和数据显示图表。
			swChart.setOption(option);
		       
		}
            init();


    </script>
</body>
</html>